<template>
  <el-dialog width="500px" title="新增角色" :visible="showDialog" @close="hClose">
    <!-- 表单内容 -->
    <el-form ref="formData" :model="formData" :rules="rules" label-width="120px">
      <el-form-item prop="name" label="角色名称">
        <el-input v-model="formData.name" style="width:300px" size="mini" />
      </el-form-item>
      <el-form-item label="启用">
        <el-switch
          v-model="formData.state"
          size="mini"
          active-color="#13ce66"
          inactive-color="#dcdfe6"
          :active-value="1"
          :inactive-value="0"
        > />
        </el-switch></el-form-item>
      <el-form-item prop="description" label="角色描述">
        <el-input v-model="formData.description" type="textarea" :rows="3" style="width:300px" size="mini" />
      </el-form-item>
      <el-form-item>
        <el-row type="flex" justify="center">
          <el-col :span="12">
            <el-button type="primary" size="mini" @click="getRole">确定</el-button>
            <el-button size="mini" @click="hClose">取消</el-button>
          </el-col>
        </el-row>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
import { upRoleList } from '@/api/role'
export default {
  props: {
    showDialog: {
      type: Boolean
    }
  },
  data() {
    return {
      formData: {
        name: '',
        state: 0,
        description: ''
      },
      rules: {
        name: [{ required: true, message: '角色名称不能为空', trigger: 'blur' }],
        description: [{ required: true, message: '角色描述不能为空', trigger: 'blur' }]
      }
    }
  },
  methods: {
    hClose() {
      this.$emit('updateOn')
      this.$refs.formData.resetFields()
    },
    async getRole() {
      await upRoleList(this.formData)
      this.hClose()
      this.$message.success('添加成功')
    }
  }
}
</script>

<style>

</style>
